package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */

@Service
public class DtsUserServiceImpl implements DtsUserService {
    @Autowired
    DtsUserMapper userMapper;

    @Autowired
    StatMapper statMapper;

    @Override
    public Integer findTotal() {
        LambdaQueryWrapper<DtsUser> wrapper
                = new LambdaQueryWrapper<>();

        wrapper.eq(DtsUser::getDeleted ,false);

        Integer count = userMapper.selectCount(wrapper);

        return count;
    }

    @Override
    public List<DayStatis> queryDayStatis(int rang) {
        return statMapper.queryUserStatis(rang);
    }

    @Override
    public IPage<DtsUser> queryPage(Integer page, Integer limit, String sort, String order) {
        IPage<DtsUser> ipage = new Page<>(page , limit);

        QueryWrapper<DtsUser> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", false);

        if(order.equalsIgnoreCase("asc")){
            wrapper.orderByAsc(sort);
        }else{
            wrapper.orderByDesc(sort);
        }

        ipage = userMapper.selectPage(ipage, wrapper);

        return ipage;
    }
}
